package com.aivin.waterfallflow;

import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.aivin.waterfallflow.tool.LoadingDialogUtils;
import com.aivin.waterfallflow.tool.MyDeviceInforHelper;

public class BaseActivity extends AppCompatActivity {

    // region  加载等待框
    protected Dialog iosLoadingDialog;
    public void showLoadDialog() {
        if (iosLoadingDialog == null) {
            iosLoadingDialog = LoadingDialogUtils.getLoadingDialogInstance(this);
        }

        if (!iosLoadingDialog.isShowing()) {
            iosLoadingDialog.show();
        }
    }

    public void hideLoadDialog() {
        if (iosLoadingDialog != null) {
            iosLoadingDialog.dismiss();
        }
    }

    private TextView loadingInfo ;
    public void setDialogLoadingINfo(String msg){
        if (iosLoadingDialog == null) {
            iosLoadingDialog = LoadingDialogUtils.getLoadingDialogInstance(this);
        }

        if(loadingInfo==null){
            LayoutInflater inflater = LayoutInflater.from(this);
            View v = inflater.inflate(R.layout.wk_loading_dialog, null);
            LinearLayout layout = v.findViewById(R.id.dialog_view);
            loadingInfo = layout.findViewById(R.id.loadingInfo);
            int width = MyDeviceInforHelper.getWidth(this);
            int height = MyDeviceInforHelper.getRealHeight( this) ;
            ViewGroup.LayoutParams layoutParams = new  ViewGroup.LayoutParams(  width   , height);
            iosLoadingDialog.setContentView(layout, layoutParams );
            layout.setBackgroundColor(Color.parseColor("#80000000"));// 设置自定义背景颜色
            iosLoadingDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));// 设置window背景
            iosLoadingDialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        }
        loadingInfo.setText(msg);

    }
    // endregion
}
